<template>
  <div>

    <el-row class="bread-nav">
      <ul class="bread-nav-title" v-if="infoParent.level === 0">
        <span>庄家->{{opera=="edit"?"修改":"新增"}}</span>
      </ul>
      <ul class="bread-nav-title" v-else>
        <span>{{infoParent.class}}级{{form.type==1?'':'会员'}}->{{opera=="edit"?"修改":"新增"}}</span>
      </ul>
      <ul class="bread-nav-content-right">
        <a class="back" @click="goBack">返回</a>
      </ul>
    </el-row>

    <div class="content">
    <el-row v-if="opera=='edit'">
      <div>
        <ul>
          <li class="topNavTitle">
            <button class="topNav topNavSelected">
              基本资料
            </button>
            <button @click="goComm" class="topNav">
              退水设定
            </button>
            <button v-if="parseInt(info.level) === 0 || parseInt(info.level) === 1" class="topNav" @click="goOdds">
              赔率差设定
            </button>
          </li>
        </ul>
      </div>
    </el-row>
        <table class="myTable">
          <thead>

          <tr>
            <th colspan="4">
            账户资料
            </th>
          </tr>
          </thead>
          <tbody>
            <tr class="myTableTr">
              <td class="deepColor textRight" colspan="1">
                {{infoParent.class}}账号
              </td>
              <td class="textLeft" v-if="infoParent.level === 0">
                总监账号
              </td>
              <td class="textLeft" colspan="4" v-else>
                {{infoParent.username}}
              </td>
            </tr>

            <tr class="myTableTr">
              <td class="deepColor textRight" colspan="1">
                {{changeNumToChinese(parseInt(infoParent.level)+1)}}级{{userTypeName}}账号
              </td>
              <td class="textLeft" colspan="4">
                <span v-if="opera=='edit'">
                  {{form.username}}
                </span>
                <input v-else type="text" v-model="form.username"  placeholder="字母和数字组合">
                <ul v-if="opera === 'edit'" class="myTableUl">
                  【
                  <label v-for="(item, key, index) in userMap.status" :key="index">
                    <input type="radio" :value="key" v-model="form.status">
                    {{item}}
                  </label>
                  】
                </ul>
              </td>
            </tr>

            <tr class="myTableTr">
              <td class="deepColor textRight" colspan="1">
                {{requireAuth === true ?'登入密码':'输入新密码'}}
              </td>
              <td class="textLeft" colspan="4">
                <input type="text" v-model="form.user_auth_key" max="32" placeholder="6-32位字母和数字组合">
              </td>
            </tr>

            <tr class="myTableTr">
              <td class="deepColor textRight" colspan="1">
                {{changeNumToChinese(parseInt(infoParent.level)+1)}}级{{userTypeName}}名称
              </td>
              <td class="textLeft" colspan="4">
                <input type="text" v-model="form.nickname" placeholder="字母和数字组合">
              </td>
            </tr>

            <tr class="myTableTr" v-if="(parseInt(info.level) === 0 && parseInt(infoParent.level)+1 === 1) || parseInt(infoParent.deal_mode) === 3">
              <td class="deepColor textRight" colspan="1">
                交易模式
              </td>
              <td class="textLeft" colspan="4">
                <label>
                  <input type="radio" :value="1" v-model="form.reset_mode"/>
                  现金
                </label>
                <label>
                  <input type="radio" :value="2" v-model="form.reset_mode"/>
                  信用
                </label>
                <label v-if="parseInt(form.type) === 1">
                  <input type="radio" :value="3" v-model="form.reset_mode"/>
                  现金+信用
                </label>
              </td>
            </tr>

            <tr class="myTableTr" v-if="parseInt(info.level) === 0 && opera == 'add' && parseInt(infoParent.level)+1 === 1">
              <td class="deepColor textRight" colspan="1">
                调整赔率差
              </td>
              <td class="textLeft" colspan="4">
                <label>
                  <input type="radio" :value="0" v-model="form.control_odds"/>
                  禁止
                </label>
                <label>
                  <input type="radio" :value="1" v-model="form.control_odds"/>
                  允许
                </label>
              </td>
            </tr>
<!-- 甲方说不要了，留着，怕又变了-->
            <!--<tr class="myTableTr" v-if="parseInt(info.level) === 0 && opera == 'add' && parseInt(infoParent.level)+1 === 1">-->
              <!--<td class="deepColor textRight" colspan="1">-->
                <!--补货占成模式-->
              <!--</td>-->
              <!--<td class="textLeft" colspan="4">-->
                <!--<label>-->
                  <!--<input type="radio" :value="0" v-model="form.replenishment_share_mode"/>-->
                  <!--未开放补货-->
                <!--</label>-->
                <!--<label>-->
                  <!--<input type="radio" :value="1" v-model="form.replenishment_share_mode"/>-->
                  <!--全归庄家-->
                <!--</label>-->
                <!--<label>-->
                  <!--<input type="radio" :value="2" v-model="form.replenishment_share_mode"/>-->
                  <!--全归一级代理-->
                <!--</label>-->
                <!--<label>-->
                  <!--<input type="radio" :value="3" v-model="form.replenishment_share_mode"/>-->
                  <!--按各级占成分配-->
                <!--</label>-->
                <!--<label>-->
                  <!--<input type="radio" :value="4" v-model="form.replenishment_share_mode"/>-->
                  <!--全归上级-->
                <!--</label>-->
                <!--<label>-->
                  <!--<input type="radio" :value="5" v-model="form.replenishment_share_mode"/>-->
                  <!--上线代理拦截-->
                <!--</label>-->
              <!--</td>-->
            <!--</tr>-->

            <!--<tr class="myTableTr" v-if="parseInt(info.level) === 0 && opera == 'add' && parseInt(infoParent.level)+1 === 1">-->
              <!--<td class="deepColor textRight" colspan="1">-->
                <!--剩余成数归属-->
              <!--</td>-->
              <!--<td class="textLeft" colspan="4">-->
                <!--<label>-->
                  <!--<input type="radio" :value="1" v-model="form.left_share_owner"/>-->
                  <!--庄家-->
                <!--</label>-->
                <!--<label>-->
                  <!--<input type="radio" :value="2" v-model="form.left_share_owner"/>-->
                  <!--一级代理-->
                <!--</label>-->
              <!--</td>-->
            <!--</tr>-->

            <tr v-if="form.reset_mode == 1 || form.reset_mode == 3 || parseInt(infoParent.level) === 0 && (parseInt(infoParent.level)+1 === 1 && (form.reset_mode == 1 || form.reset_mode == 3))" class="myTableTr">
              <td class="deepColor textRight" colspan="1">
                快开彩现金额度
              </td>
              <td class="textLeft" colspan="4">
                <div v-if="opera == 'add'">
                  <div v-if="parseInt(infoParent.level) === 0">
                    <input type="number" v-model="form.qk_cash_amount" :max="2000000000" :min="0">
                    <span>
                    (2,000,000,000)
                  </span>
                  </div>
                  <div v-else>
                    <input type="number" v-model="form.qk_cash_amount" :max="infoParent.qk_cash" :min="0">
                    <span>
                    (上级余额：{{infoParent.qk_cash}})
                  </span>
                  </div>
                </div>
                <div v-if="opera == 'edit'">
                  <span>
                    {{form.qk_cash_amount}}
                  </span>
                  <button @click="changeCash(1, form.qk_cash_amount, 1)" class="tableBtn">
                    修改
                  </button>
                  <!--<input type="number" v-model="form.qk_cash_amount" :max="infoParent.qk_cash" :min="0"> (上级余额:{{infoParent.qk_cash}},自身余额:{{infoUser.qk_cash_amount}})-->
                  <!--<el-input-number size="small" v-model="form.qk_cash_amount" :min=0 :max="infoParent.qk_cash_amount/1+infoUser.hk_cash/1"></el-input-number> (上级余额:{{infoParent.qk_cash}},自身余额:{{infoUser.qk_cash_amount}})-->
                </div>
              </td>
            </tr>

            <tr class="myTableTr" v-if="form.reset_mode == 2 || form.reset_mode == 3 || parseInt(infoParent.level) === 0 && (parseInt(infoParent.level)+1 === 1 && (form.reset_mode == 2 || form.reset_mode == 3))">
              <td class="deepColor textRight" colspan="1">
                快开彩信用额度
              </td>
              <td class="textLeft" colspan="4">
                <div v-if="opera == 'add'">
                  <div v-if="parseInt(infoParent.level) === 0">
                    <input type="number" v-model="form.qk_credit_amount" :max="2000000000" :min="0">
                    <span>
                    (2,000,000,000)
                  </span>
                  </div>
                  <div v-else>
                    <input type="number" v-model="form.qk_credit_amount" :max="infoParent.qk_credit" :min="0">
                    <span>
                    (上级余额：{{infoParent.qk_credit}})
                  </span>
                  </div>
                </div>
                <div v-if="opera == 'edit'">
                  <span>
                    {{form.qk_credit_amount}}
                  </span>
                  <button @click="changeCash(1, form.qk_credit_amount, 2)" class="tableBtn">
                    修改
                  </button>
                  <!--<input type="number" v-model="form.qk_credit_amount" :max="infoParent.qk_credit" :min="0">(上级余额:{{infoParent.qk_credit}},自身余额:{{infoUser.qk_credit}})-->
                  <!--<el-input-number size="small" v-model="form.qk_credit_amount" :min=0 :max="infoParent.qk_credit_amount/1+infoUser.qk_credit/1"></el-input-number> (上级余额:{{infoParent.qk_credit}},自身余额:{{infoUser.qk_credit}})-->
                </div>
              </td>
            </tr>

            <tr class="myTableTr" v-if="form.reset_mode == 1 || form.reset_mode == 3 || parseInt(infoParent.level) === 0 && (parseInt(infoParent.level)+1 === 1 && (form.reset_mode == 1 || form.reset_mode == 3))">
              <td class="deepColor textRight" colspan="1">
                香港彩现金额度
              </td>
              <td class="textLeft" colspan="4">
                <div v-if="opera == 'add'">
                  <div v-if="parseInt(infoParent.level) === 0">
                    <input type="number" v-model="form.hk_cash_amount" :max="2000000000" :min="0">
                    <span>
                     (2,000,000,000)
                  </span>
                  </div>
                  <div v-else>
                    <input type="number" v-model="form.hk_cash_amount" :max="infoParent.hk_cash" :min="0">
                    <span>
                    (上级余额：{{infoParent.hk_cash}})
                  </span>
                  </div>
                </div>
                <div v-if="opera == 'edit'">
                  <span>
                    {{form.hk_cash_amount}}
                  </span>
                  <button @click="changeCash(2, form.hk_cash_amount, 1)" class="tableBtn">
                    修改
                  </button>
                  <!--<input type="number" v-model="form.hk_cash_amount"  :max="infoParent.hk_cash" :min="0">-->
                  <!--(上级余额:{{infoParent.hk_cash}},自身余额:{{infoUser.hk_cash_amount}})-->
                  <!--<el-input-number size="small" v-model="form.hk_cash_amount" :min=0 :max="infoParent.hk_cash_amount/1+infoUser.hk_cash_amount/1"></el-input-number> (上级余额:{{infoParent.hk_cash}},自身余额:{{infoUser.hk_cash_amount}})-->
                </div>
              </td>
            </tr>

            <tr class="myTableTr" v-if="form.reset_mode == 2 || form.reset_mode == 3 || parseInt(infoParent.level) === 0 && (parseInt(infoParent.level)+1 === 1 && (form.reset_mode == 2 || form.reset_mode == 3))">
              <td class="deepColor textRight" colspan="1">
                香港彩信用额度
              </td>
              <td class="textLeft" colspan="4">
                <div v-if="opera == 'add'">
                  <div v-if="parseInt(infoParent.level) === 0">
                    <input type="number" v-model="form.hk_credit_amount" :max="2000000000" :min="0">
                    <span>
                     (2,000,000,000)
                  </span>
                  </div>
                  <div v-else>
                    <input type="number" v-model="form.hk_credit_amount" :max="infoParent.hk_credit" :min="0">
                    <span>
                    (上级余额：{{infoParent.hk_credit}})
                  </span>
                  </div>
                </div>
                <div v-if="opera == 'edit'">
                  <span>
                    {{form.hk_credit_amount}}
                  </span>
                  <button @click="changeCash(2, form.hk_credit_amount, 2)" class="tableBtn">
                    修改
                  </button>
                  <!--<input type="number" v-model="form.hk_credit_amount"  :max="infoParent.hk_credit" :min="0">(上级余额:{{infoParent.hk_credit}},自身余额:{{infoUser.hk_credit}})-->
                  <!--<el-input-number size="small" v-model="form.hk_credit_amount" :min=0 :max="infoParent.hk_credit_amount/1+infoUser.hk_credit_amount/1"></el-input-number> (上级余额:{{infoParent.hk_credit}},自身余额:{{infoUser.hk_credit}})-->
                </div>
              </td>
            </tr>

            <tr class="myTableTr">
              <td class="deepColor textRight" colspan="1">
                开放盘口
              </td>
              <td class="textLeft" colspan="4">
                <ul v-if="form.type == 1 && infoParent.level !== 0">
                  <label v-for="item in infoParent.handicaps">
                    <input type="checkbox" :value="item" v-model="form.handicaps">
                    {{userMap.handicaps[item]}}盘
                  </label>
                </ul>
                <ul v-if="form.type == 1 && infoParent.level === 0">
                  <label v-for="(item,key) in userMap.handicaps">
                    <input type="checkbox" :value="key" v-model="form.handicaps">
                    {{item}}盘
                  </label>
                </ul>

                <ul v-if="form.type == 2 && infoParent.level !== 0">
                  <label v-for="item in infoParent.handicaps">
                    <input type="radio" :value="item"  v-model="form.handicaps">
                    {{userMap.handicaps[item]}}盘
                  </label>
                </ul>

                <ul v-if="form.type == 2 && infoParent.level === 0">
                  <label v-for="(item,key) in userMap.handicaps">
                    <input type="radio" :value="key"  v-model="form.handicaps">
                    {{item}}盘
                  </label>
                </ul>
              </td>
            </tr>

            <tr class="myTableTr" v-if="opera == 'add'">
              <td class="deepColor textRight" colspan="1">
                赚取退水
              </td>
              <td class="textLeft" colspan="3">
                <select v-model="form.earn_commission" placeholder="选择退水比例">
                  <option v-for="item in userMap.earn_commission" :value="Object.keys(item)[0]">
                    {{Object.values(item)[0]}}
                  </option>
                </select>
              </td>
            </tr>
          </tbody>
        </table>

      <table class="myTable">
        <thead>
          <tr>
          <th :colspan="form.type == 1?'6':'3'">
            占成设置
          </th>
          </tr>
        </thead>
        <tbody>

          <tr>
            <td :rowspan="form.type == 1?2:1" class="deepColor">
              类型
            </td>
            <td v-if="form.type == 1" :rowspan="form.type == 1?2:1" class="deepColor">
              <span v-if="infoParent.level === 0">总监最高占成</span>
              <span v-else>{{infoParent.class}}最高占成</span>
            </td>
            <td :colspan="form.type == 1?2:1" class="deepColor">
              {{form.type == 1? changeNumToChinese( parseInt(infoParent.level) + 1 ) + '级代理':'代理'}}占成
            </td>
            <td v-if="form.type != 1" class="deepColor">
              {{form.type == 1?'占成条件':'可分配占成'}}
            </td>
            <td v-if="form.type == 1" :rowspan="form.type == 1?2:1" class="deepColor">
              开放补货
            </td>
            <!--甲方说不要了，留着，怕又变了-->
            <!--<td v-if="form.type == 1" :rowspan="form.type == 1?2:1" class="deepColor">-->
              <!--拦截补货-->
            <!--</td>-->
          </tr>
        <tr v-if="form.type == 1">
          <td class="deepColor">
            最低（%）
          </td>
          <td class="deepColor">
            最高（%）
          </td>
        </tr>

      <tr class="myTableTr">
        <td class="deepColor textRight">
          <span class="spanRed" v-if="infoUser.qk_has_order === 1">【预设】</span>快开彩种
        </td>
        <td>
          <span class="spanRed" v-if="infoUser.qk_has_order === 1">{{infoUser.qk_upper_share_default}}</span>
          <input type="number" v-model="form.qk_upper_level_share" :max="shareCon.qk_max_share" :min="shareCon.qk_min_share">%( {{shareCon.qk_min_share}}% 至 {{shareCon.qk_max_share}}% )
        </td>
        <td  v-if="form.type==1">
          <span class="spanRed" v-if="infoUser.qk_has_order === 1">{{infoUser.qk_min_share_default}}</span>
          <input type="number" v-model="form.qk_self_min_share" :max="shareCon.qk_max_share" :min="shareCon.qk_min_share">%
        </td>
        <td  v-if="form.type==1">
          <span class="spanRed" v-if="infoUser.qk_has_order === 1">{{infoUser.qk_max_share_default}}</span>
          <input type="number" v-model="form.qk_self_max_share" :max="shareCon.qk_max_share" :min="shareCon.qk_min_share">%(最高{{shareCon.qk_max_share}}% )
        </td>
        <td v-if="form.type != 1">
          ( {{shareCon.qk_min_share}}% 至 {{shareCon.qk_max_share}}% )
        </td>
        <td v-if="form.type == 1">
          <label>
            <input type="radio" :disabled="infoUser.qk_padding_enabled === 0 || (parseInt(infoParent.qk_padding) === 0 && form.qk_open_replenishment === 0) ? true : false" v-model="form.qk_open_replenishment" :value="1">
            开放
          </label>
          <label>
            <input type="radio" :disabled="infoUser.qk_padding_enabled === 0 || (parseInt(infoParent.qk_padding) === 0 && form.qk_open_replenishment === 0) ? true : false" v-model="form.qk_open_replenishment" :value="0">
            禁止
          </label>
        </td>
        <!--甲方说不要了，留着，怕又变了-->
        <!--<td v-if="form.type == 1">-->
          <!--<label>-->
            <!--<input type="radio" v-model="form.qk_catch_replenishment" :value="1">-->
            <!--开放-->
          <!--</label>-->
          <!--<label>-->
            <!--<input type="radio" v-model="form.qk_catch_replenishment" :value="0">-->
            <!--禁止-->
          <!--</label>-->
        <!--</td>-->
      </tr>

        <tr class="myTableTr">
          <td class="deepColor textRight">
            <span class="spanRed" v-if="infoUser.hk_has_order === 1">【预设】</span>香港彩种
          </td>
          <td>
            <span class="spanRed" v-if="infoUser.hk_has_order === 1">{{infoUser.hk_upper_share_default}}</span>
            <input type="number" v-model="form.hk_upper_level_share" :max="shareCon.hk_max_share" :min="shareCon.hk_min_share">%( {{shareCon.hk_min_share}}% 至 {{shareCon.hk_max_share}}% )
          </td>
          <td  v-if="form.type==1">
            <span class="spanRed" v-if="infoUser.hk_has_order === 1">{{infoUser.hk_min_share_default}}</span>
            <input type="number" v-model="form.hk_self_min_share" :max="shareCon.hk_max_share" :min="shareCon.hk_min_share">%
          </td>
          <td  v-if="form.type==1">
            <span class="spanRed" v-if="infoUser.hk_has_order === 1">{{infoUser.hk_max_share_default}}</span>
            <input type="number" v-model="form.hk_self_max_share" :max="shareCon.hk_max_share" :min="shareCon.hk_min_share" >%(最高{{shareCon.hk_max_share}}% )
          </td>
          <td v-if="form.type != 1">
            ( {{shareCon.hk_min_share}}% 至 {{shareCon.hk_max_share}}% )
          </td>
          <td v-if="form.type == 1">
            <label>
              <input type="radio" :disabled="infoUser.hk_padding_enabled === 0 || (parseInt(infoParent.hk_padding) === 0 && form.hk_open_replenishment === 0) ? true : false" v-model="form.hk_open_replenishment" :value="1">
              开放
            </label>
            <label>
              <input type="radio" :disabled="infoUser.hk_padding_enabled === 0 || (parseInt(infoParent.hk_padding) === 0 && form.hk_open_replenishment === 0) ? true : false" v-model="form.hk_open_replenishment" :value="0">
              禁止
            </label>
          </td>
          <!--甲方说不要了，留着，怕又变了-->
          <!--<td v-if="form.type == 1">-->
            <!--<label>-->
              <!--<input type="radio" v-model="form.hk_catch_replenishment" :value="1">-->
              <!--开放-->
            <!--</label>-->
            <!--<label>-->
              <!--<input type="radio" v-model="form.hk_catch_replenishment" :value="0">-->
              <!--禁止-->
            <!--</label>-->
          <!--</td>-->
        </tr>

        </tbody>

      </table>

    <div class="baseOdd-bottom">
      <button @click="onSubmit">确认</button>
      <button @click="onReset">重置</button>
    </div>
    </div>

    <div id="dialog"  class="myDialog" style="display:none;">
      <div class="myDialogDiv">
        <table class="myTable">
          <tr>
            <td class="deepColor textRight">
              账号
            </td>
            <td class="textLeft">
              {{amountInfo.username}}
            </td>
          </tr>
          <tr>
            <td class="deepColor textRight">
              {{amountType}}额度
            </td>
            <td class="textLeft">
              {{lotteryAmount}}
              <button @click="WithdrawAll">
                提取全部额度
              </button>
            </td>
          </tr>
          <tr>
            <td class="deepColor textRight">
              上级可用额度
            </td>
            <td class="textLeft">
              {{upLotteryAmount}}
            </td>
          </tr>
          <tr>
            <td class="deepColor textRight">
              类型
            </td>
            <td class="textLeft">
              <label>
                <input type="radio" :value="1" v-model="amountInfo.oper_type">
                存款
              </label>
              <label>
                <input type="radio" :value="2" v-model="amountInfo.oper_type">
                提款
              </label>
            </td>
          </tr>
          <tr>
            <td class="deepColor textRight">
              金额
            </td>
            <td class="textLeft">
              <input type="text" v-model="amountInfo.amount">
            </td>
          </tr>
          <tr>
            <td class="deepColor textRight">
            </td>
            <td class="textLeft">
              <button @click="ValidateChangeAmount">
                确定
              </button>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
import { user as userMap } from '@/utils/map' // 参数映射
import { NumberToChinese } from '@/utils/transformNum'
import $ from 'jquery'
import 'jquery-ui/ui/widgets/dialog'
import { mapGetters } from 'vuex'
export default {
  name: 'set',
  data() {
    return {
      infoParent: {}, // 父级账号信息
      infoUser: {}, // 新增或待编辑账号信息
      userMap: userMap,
      opera: null, // 操作:新增,修改
      userTypeName: null, // 代理,会员
      loading: false,
      qkCatckDisabled: false, // 拦截switch
      hkCatckDisabled: false, // 拦截switch
      hasOrder: false, // 是否已经投标
      form: {
        username: '',
        nickname: '',
        type: 1, // 默认1:agent,2:member
        status: 1,
        user_auth_key: '',
        handicaps: [],
        qk_upper_level_share: 0,
        qk_cash_amount: 0,
        qk_credit_amount: 0,
        qk_open_replenishment: '1',
        // qk_catch_replenishment: '0', // 拦截    ----甲方说不要了，留着，怕又变了
        qk_self_min_share: 0,
        qk_self_max_share: 0,
        hk_upper_level_share: 0,
        hk_self_min_share: 0,
        hk_self_max_share: 0,
        hk_cash_amount: 0,
        hk_credit_amount: 0,
        hk_open_replenishment: '1',
        // hk_catch_replenishment: '0', // 拦截    ----甲方说不要了，留着，怕又变了
        earn_commission: null, // 赚取退水
        p_agentname: '', // 非必须 本来是p_agentname，接口那里写错了，就顺着他们写错吧
        reset_mode: 1, // 非必须1:现金,2信用,3现金-信用
        // left_share_owner: '1', // 剩余成数归属     ----甲方说不要了，留着，怕又变了
        control_odds: '0', // 调整赔率差
        // replenishment_share_mode: '1', // 补货占成模式      ----甲方说不要了，留着，怕又变了
      },
      amountInfo: '',
      amountType: '',
      lotteryAmount: 0,
      upLotteryAmount: 0,
      commParams: '', // 退水编辑参数
      shareCon: '',
    }
  },
  computed: {
    ...mapGetters(['info', 'gameOptions']),
    requireAuth() {
      return this.opera === 'add'
    },
  },
  created() {
    this.checkParams()
    this.form.earn_commission = Object.keys(this.userMap.earn_commission[0])[0]
    this.commParams = this.$route.params
  },
  methods: {
    changeNumToChinese(num) {
      return NumberToChinese(num)
    },
    getShareConditions() {
      this.$store.dispatch('getShareConditions', {
        p_agentname: this.infoParent.username,
      })
        .then(response => {
          this.shareCon = response
        })
    },
    goOdds() {
      this.$router.push({
        name: 'user_odds',
        params: this.setParams,
      })
    },
    goComm() {
      this.$router.push({
        name: 'user_commission',
        params: this.commParams,
      })
    },
    ValidateChangeAmount() {
      if (this.amountInfo.amount === null) {
        alert('金额不能为空')
      }
      if (this.amountInfo === 0 === null) {
        alert('请选择类型')
      } else {
        // console.log(this.amountInfo, '111111111111111')
        this.$store.dispatch('ValidateChangeAmount', { ChangeAmountForm: this.amountInfo })
          .then(response => {
            // console.log(response, '22222222222222222')
            if (response.status) {
              this.$store.dispatch('ChangeAmount', { ChangeAmountForm: this.amountInfo })
                .then(response => {
                  if (response.status === true) {
                    console.log('11111111',response)
                    alert(response.message)
                    $('#dialog').dialog('destroy')

                    // $('.myDialog').css({
                    //   display: 'none',
                    // })
                    // $('.ui-dialog-titlebar').css({
                    //   display: 'none',
                    // })
                    // $('.ui-dialog').css({
                    //   padding: 0,
                    //   border: 'none',
                    // })
                    this.checkParams()
                    // console.log($('#dialog'))
                    // console.log($('#dialog').dialog('close'))
                    // console.log(this.checkParams(), '5555555555')
                    // console.log(Object.values(response.message)[0].toString(), '666666666666666')
                    // console.log(Object.values(response.message)[0].toString(), '8888888888888')
                  } else {
                    alert(Object.values(response.message)[0].toString())
                  }
                })
            } else {
              alert(Object.values(response.message)[0].toString())
            }
          })
      }
    },
    WithdrawAll() {
      const params = {
        username: this.amountInfo.username,
        l_type: this.amountInfo.lottery_type,
        mode: this.amountInfo.mode,
      }
      if (window.confirm('是否确定抽取额度吗？')) {
        this.$store.dispatch('WithdrawAll', params)
          .then(response => {
            console.log(response.status)
            if (response.status) {
              alert(response.message)
              $('#dialog').dialog('destroy')
              this.checkParams()
            } else {
              alert(response.message)
            }
          })
        return true
      } else {
        return false
      }
    },
    changeCash(type, value, mode) {
      if (mode === 1) { // 1现2信
        if (type === 1) { // 1快2港
          this.amountType = '快开彩'
          this.upLotteryAmount = this.infoParent.qk_cash
        } else {
          this.amountType = '香港彩'
          this.upLotteryAmount = this.infoParent.hk_cash
        }
      } else {
        if (type === 1) {
          this.amountType = '快开彩信用'
          this.upLotteryAmount = this.infoParent.qk_credit
        } else {
          this.amountType = '香港彩信用'
          this.upLotteryAmount = this.infoParent.hk_credit
        }
      }
      this.lotteryAmount = value
      const temp = {
        username: this.form.username,
        amount: null,
        lottery_type: type,
        oper_type: null,
        mode: mode,
      }
      this.amountInfo = temp
      $('#dialog').dialog({
        width: 430,
      })
      // $('#dialog').css({
      //   display: 'block',
      // })
      // $('.ui-dialog-titlebar').css({
      //   display: 'block',
      // })
      // $('.ui-dialog').css({
      //   padding: '.2em',
      //   border: '1px solid #dddddd',
      // })
      const tmp = $('.ui-dialog-titlebar-close').children().clone()
      $('.ui-dialog-titlebar-close').html('').append(tmp)
      $('.ui-dialog-title').html(this.amountInfo.username + '#额度修改')
    },
    goBack() {
      // $('#dialog').remove()
      this.$router.go(-1)
    },

    onSubmit() {
      console.log(this.infoParent)
      console.log(this.form.type)
      this.form.username = this.form.username.trim()
      this.form.nickname = this.form.nickname.trim()
      this.form.user_auth_key = this.form.user_auth_key.trim()
      this.loading = true
      // 新增代理
      const dispatch = {
        validate: 'ValidateAgent',
        set: 'CreateAgent',
        payload: { AgentForm: this.form },
      }
      // 根据type,操作发送到不同接口
      if (this.opera === 'add' && parseInt(this.form.type) === 2) {
        // 新增会员
        dispatch.validate = 'ValidateMember'
        dispatch.set = 'CreateMember'
        dispatch.payload = { agent: this.infoParent.username, MemberForm: this.form }
      } else if (this.opera === 'edit' && parseInt(this.form.type) === 1) {
        // 更新代理
        console.log('更新代理')
        const tempForm = JSON.parse(JSON.stringify(this.form))
        delete tempForm.username
        const tempParams = {
          AgentUpdateForm: tempForm,
          username: this.form.username,
        }
        dispatch.validate = 'ValidateUpdateAgent'
        dispatch.set = 'UpdateAgent'
        dispatch.payload = tempParams
      } else if (this.opera === 'edit' && parseInt(this.form.type) === 2) {
        // 更新会员
        dispatch.validate = 'ValidateUpdateMember'
        dispatch.set = 'UpdateMember'
        const tempForm = JSON.parse(JSON.stringify(this.form))
        delete tempForm.username
        const tempParams = {
          MemberUpdateForm: tempForm,
          username: this.form.username,
        }
        dispatch.payload = tempParams
      }
      console.log(dispatch.validate, dispatch.payload, dispatch.set)

      this.$store
        .dispatch(dispatch.validate, dispatch.payload)
        .then(response => {
          this.loading = false
          this.errorMsg = ''
          if (response.status) {
            // 服务端验证通过
            this.$store
              .dispatch(dispatch.set, dispatch.payload)
              .then(res => {
                if (res.status) {
                  // 新增成功成功
                  alert(res.message)
                  // const newId = parseInt(res) // 新代理id
                  // 跳转到退水设置
                  // 跳转到 list
                  // this.$router.push({ path: "/change-pwd" });
                  if (this.opera === 'add') {
                    const messTip = confirm('保存成功，是否设置退水？')
                    if (messTip === true) {
                      this.$router.push({
                        name: 'user_commission',
                        params: {
                          username: this.form.username,
                          level: parseInt(this.infoParent.level) + 1,
                          opera: 'edit', // 操作类型
                          isGoBack: true, // 是否返回用户列表
                        },
                      })
                    } else {
                      this.$router.go(-1)
                    }
                  } else {
                    this.$router.go(-1)
                  }
                } else {
                  alert(Object.values(res.message)[0].toString())
                }
              })
          } else {
            console.log(dispatch.payload)
            // 验证失败
            alert(Object.values(response.message)[0].toString())
          }
        })
    },
    // 重置信息
    onReset() {
      this.$router.go(-1)
      // // 返回列表
      // this.$refs.form.resetFields()
      // this.$message({
      //   message: '数据已重置!',
      //   type: 'warning',
      // })
    },
    // 验证参数
    checkParams() {
      // 用户
      this.form.p_agentname = this.$route.params.parent
      this.form.type = this.$route.params.type
      this.userTypeName = parseInt(this.$route.params.type) === 1 ? '代理' : '会员'
      this.opera = this.$route.params.opera // 操作
      this.getInfoParent()
    },

    // 验证是否已有投标
    checkHasOrder() {
      this.$store
        .dispatch('HasOrder', { username: this.$route.params.username })
        .then(response => {
          this.hasOrder = response
        })
    },

    // 查询对应agentName的账号信息
    getInfoParent() {
      this.loading = true
      this.$store
        .dispatch('GetUserInfo', { username: this.form.p_agentname })
        .then(response => {
          this.loading = false
          this.infoParent = response
          // 预设开放补货
          if (parseInt(this.infoParent.qk_padding) === 0) {
            this.form.qk_open_replenishment = 0
          }
          if (parseInt(this.infoParent.hk_padding) === 0) {
            this.form.hk_open_replenishment = 0
          }
          // 将,号字符转换成数组,用于radio的遍历输出
          if (typeof response.handicaps === 'string') {
            this.infoParent.handicaps = response.handicaps.split(',')
          }
          if (Array.isArray(this.infoParent.handicaps)) {
            const length = this.infoParent.handicaps.length
            let tempArray, minIndex
            for (let i = 0; i < length - 1; i++) {
              minIndex = i
              for (let j = i + 1; j < length; j++) {
                if (parseInt(this.infoParent.handicaps[j]) < parseInt(this.infoParent.handicaps[minIndex])) {
                  minIndex = j
                }
              }
              tempArray = this.infoParent.handicaps[i]
              this.infoParent.handicaps[i] = this.infoParent.handicaps[minIndex]
              this.infoParent.handicaps[minIndex] = tempArray
            }
          }
          if (this.opera === 'edit') {
            // 将infoParent赋值给form
            this.getInfoUser()
          }
          console.log('123456789456123456789', this.infoParent)
          this.getShareConditions()
        })
    },
    // 当编辑时,获取用户数据
    getInfoUser() {
      this.$store
        .dispatch('GetUserInfo', { username: this.$route.params.username })
        .then(response => {
          this.infoUser = response // 保存用户信息
          // 将要修改的用户信息赋值给form对应的字段
          if (parseInt(this.form.type) === 1) {
            // 代理的盘口要转换为数组,多选.  会员是单选,是字符
            if (Array.isArray(response.handicaps)) {
              this.form.handicaps = response.handicaps
            } else {
              this.form.handicaps.push(parseInt(response.handicaps))
            }
          } else {
            this.form.handicaps = parseInt(response.handicaps[0]) // 注意将number转换成string,否则控件取值不能匹配
          }
          this.form.username = response.username
          this.form.nickname = response.nickname
          this.form.status = response.account_status
          this.form.qk_upper_level_share = response.qk_upper_share
          this.form.qk_cash_amount = response.qk_cash
          this.form.qk_self_min_share = response.qk_min_share
          this.form.qk_self_max_share = response.qk_max_share
          this.form.qk_credit_amount = response.qk_credit

          this.form.hk_upper_level_share = response.hk_upper_share
          this.form.hk_cash_amount = response.hk_cash
          this.form.hk_credit_amount = response.hk_credit
          this.form.hk_self_min_share = response.hk_min_share
          this.form.hk_self_max_share = response.hk_max_share

          this.form.earn_commission = parseFloat(response.earn_commission, 10)
          // switch 值不认 number的值,所以要转换成string
          this.form.qk_open_replenishment = response.qk_padding
          this.form.hk_open_replenishment = response.hk_padding
          // this.form.qk_catch_replenishment = response.qk_captrue_padding    ----甲方说不要了，留着，怕又变了
          // this.form.hk_catch_replenishment = response.hk_captrue_padding     ----甲方说不要了，留着，怕又变了

          this.form.reset_mode = response.deal_mode
          // this.form.left_share_owner = response.remaining_share_owner   ----甲方说不要了，留着，怕又变了
          this.form.control_odds = response.odds_manage
          // this.form.replenishment_share_mode = response.padding_share_mode   ----甲方说不要了，留着，怕又变了
          this.handleQkOpen(this.form.qk_open_replenishment) // 根据获取的值,处理拦截的按钮
          this.handleHkOpen(this.form.hk_open_replenishment)

          console.log('123456789', this.form, response)
          // 验证是否已经下单
          // this.checkHasOrder()
        })
    },
    // qkopen,hkopen 变化打开时,拦截可以操作.  当打开关闭时,拦截一起关闭
    handleQkOpen(value) {
      if (parseInt(value) === 1) {
        // 打开
        this.qkCatckDisabled = false
      } else {
        // 关闭
        this.qkCatckDisabled = true
        // this.form.qk_catch_replenishment = '0' // 同时关闭    ----甲方说不要了，留着，怕又变了
      }
    },
    handleHkOpen(value) {
      if (parseInt(value) === 1) {
        // 打开
        this.hkCatckDisabled = false
      } else {
        // 关闭
        this.hkCatckDisabled = true
        // this.form.hk_catch_replenishment = '0' // 同时关闭     ----甲方说不要了，留着，怕又变了
      }
    },
  },
}
</script>

<style scoped>

  .content{
    padding: 5px;
  }
.topNavTitle{
  height: 29px;
  line-height: 29px;
  background: url(/static/agent/img/tab_bg02.gif) repeat-x left -93px;
}
.topNav{
  display: block;
  width: 98px;
  height: 29px;
  font-size: 13px;
  color: #7d7d7d;
  background: url(/static/agent/img/tab_bg02.gif) no-repeat left -29px;
  text-shadow: 1px 1px 0 white;
  margin: 0 5px 0 0;
  text-align: center;
  float: left;
  text-decoration: none;
  border:none;
}
.topNavSelected{
  color: #274D98;
  /* font-weight: bold; */
  background: url(/static/agent/img/tab_bg02.gif) no-repeat left top;
}
.topNav:hover{
  color: #274D98;
  /* font-weight: bold; */
  background: url(/static/agent/img/tab_bg02.gif) no-repeat left top;
}

.bread-nav{
  height:30px;
  font-size: 13px;
  line-height: 30px;
  background: #ECEFF2;
  border-bottom: 1px solid #d0dff2;
  padding: 0 0 0 10px;
  overflow: hidden;
}
.bread-nav-title{
  color:#386399;
  font-weight: bold;
  float: left;
  background: url("../../../../static/agent/img/tb.png") no-repeat left center;
  padding-left: 20px;
}
.bread-nav-content-right{
  float: right;
}
.bread-nav-content-right .back{
  border:0;
  background:url(/static/agent/img/ico_back.png) no-repeat left 8px;
  color:#386399;
  display: block;
  font-weight: bold;
  margin-right: 10px;
  padding: 0 0 0 20px;
}
.bread-nav-content-right .back:hover{
  text-decoration: underline;
}

  .set-user-form{
    padding: 10px;
  }
  .set-user-form .el-form-item{
    margin: 0 !important;
    line-height: 25px;
    font-size:13px;
    border-bottom: 1px solid #b9c2cb;
    border-left: 1px solid #b9c2cb;
    border-right: 1px solid #b9c2cb;
    height:30px;
  }
  .set-user-form .el-input-number{
    height:25px;
  }
.set-user-form .el-input {
  min-width: 150px;
  max-width: 300px;
  width: 50%;
  height:25px;
}
.set-user-form .el-form-item .el-form-item__content{
  border-left: 1px solid #b9c2cb;
}
  .form-up-title{
    line-height: 25px;
    font-size:13px;
    text-align: center;
    font-weight: bold;
    color:#131950;
    background: url(/static/agent/img/table_head.gif) repeat-x;
    border: 1px solid #b9c2cb;
    margin-top: 2px;
  }

.set-user-form .el-row{
  height:25px;
  line-height: 25px;
}

.baseOdd-bottom{
  text-align: center;
  margin-top: 20px !important;
}
.baseOdd-bottom button{
  width: 86px;
  height: 31px;
  line-height: 26px;
  color: #eeeeee;
  background: url(/static/agent/img/nav_bu.png) repeat-x left -134px;
  border: 0px;
}
.baseOdd-bottom button:hover{
  color: #fff100;
  background: url(/static/agent/img/nav_bu.png) repeat-x left -165px;
}

.myTable{
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  margin: 2px  0;
  text-align: center;
}
.myTable th{
  background: url(/static/agent/img/table_head.gif) repeat-x;
  height: 25px;
  text-align: center;
  color: #344b50;;
  font-weight: bold;
  line-height: 25px;
  font-size:14px;
  padding-left: 10px;
  padding-right: 10px;
  border: 1px solid #B9C2CB;
  margin: 0;
}
.myTable td{
  text-align: center;
  color: #344b50;
  line-height: 28px;
  height: 28px;
  padding: 0 5px;
  font-size:14px;
  border: 1px solid #B9C2CB;
  box-sizing: border-box;
}
.deepColor{
  background-color: #F2F2F2;
  font-weight: bold;
}
.textLeft{
  text-align: left !important;
}
.textRight{
  text-align: right !important;
  width: 25% !important;
}
.myTable select{
  color:blue;
}
.myTableUl{
  display: inline-block;
}

.tableBtn{
  color:blue;
  background-color: rgba(0,0,0,0);
  border: none;
  outline: none;
  cursor: pointer;
}
.tableBtn:hover{
  text-decoration: underline;
}
.myTableTr:hover{
  background-color: #deedfe;
}

  .myDialog{
    background-color: #FFF;
    margin: 0;
  }
  .myDialogDiv{
    background-color: #FFF;
    width:400px;
  }
  .spanRed{
    color:red !important;
    font-weight: 600;
  }
</style>
